package my.study.org.apache.ibatis.examples.example1;

import java.io.IOException;

import my.study.org.apache.ibatis.examples.example1.bean.Blog;
import my.study.org.apache.ibatis.examples.example1.factory.SessionFactory;
import my.study.org.apache.ibatis.examples.example1.mapper.BlogMapper;

import org.apache.ibatis.session.SqlSession;

public class Example1Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		SqlSession session = SessionFactory.getInstance().openSession();
		Object date = session.selectOne("my.org.apache.ibatis.examples.example1.mapper.BlogMapper.selectCurDate");
		System.out.println(date);
		
		BlogMapper blogMapper = session.getMapper(BlogMapper.class);
		Blog blog  = blogMapper.selectByID(1);
		System.out.println(blog);
		
		Blog blog2 = (Blog) session.selectOne("my.org.apache.ibatis.examples.example1.mapper.BlogMapper.selectByID", 1);
		System.out.println(blog2);
		
		Blog blog3 = new Blog();
		blog3.setTitle("Design Pattern");
		blog3.setAuthor("Gang Of Four");
		int re = blogMapper.insertBlog(blog3);
		System.out.println(re);
		System.out.println(blog3);
		session.commit();
		
		Blog blog4 = (Blog) session.selectOne("my.org.apache.ibatis.examples.example1.mapper.BlogMapper.selectByID", blog3.getId());
		System.out.println(blog4);
		
		session.close();
	}
}
